/**
 * @Project : algorithm-learning
 * @Author : Ruoyu Wang
 * @User : Momenta
 * @DateTime : 2024/4/16 14:39
 */

#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    bool canPlaceFlowers(vector<int> &flowerbed, int n) {
        int res = 0;
        for (int i = 0; i < flowerbed.size(); ++i) {
            bool flag = flowerbed[i] == 0;
            if (i + 1 < flowerbed.size()) flag &= flowerbed[i + 1] == 0;
            if (i > 0) flag &= flowerbed[i - 1] == 0;
            if (flag) {
                res++;
                i++;
            }
        }
        return res >= n;
    }
};